@@require(PLATFORM, VERSION, isTX, sx127x)
<!DOCTYPE HTML>
<html>

<head>
	<title>Welcome to your ExpressLRS System</title>
	<meta charset="utf-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1" />
	<link rel="stylesheet" href="elrs.css" />
</head>

<body>
	<header class="mui-appbar mui--z1 mui--text-center elrs-header">
		@@include("logo-template.svg")
		<h1><b>ExpressLRS</b></h1>
		<span id="product_name"></span><br/>
		<b>Firmware Rev. </b>@@{VERSION} <span id="reg_domain"></span>
	</header>
	<br>
	<div class="mui-container-fluid mui-col-sm-10 mui-col-sm-offset-1">
		<div id="custom_config" class="mui-panel" style="display:none; background-color: #FFC107;">
			This hardware configuration has been customised. This can be safely ignored if this is a custom hardware build or for testing purposes.<br>
			You can <a download href="/hardware.json">download</a> the configuration or <a href="/reset?hardware">reset</a> to pre-configured defaults and reboot.
		</div>
		<div class="mui-panel">
			<form id="notused" action="" method="POST" enctype="multipart/form-data">
				<fieldset>
					<input type="hidden" id="MAX_FILE_SIZE" name="MAX_FILE_SIZE" value="10000" />
					<div>
						<label for="fileselect">Load target configuration (remember to press "Save Target Configuration" below):</label>
						<input type="file" id="fileselect" name="fileselect[]" />
						<div id="filedrag">or drop files here</div>
					</div>
				</fieldset>
			</form>
		</div>
		<div class="mui-panel">
			<form id='upload_hardware' method='POST' action="/hardware">
				<input type="hidden" id="customised" name="customised" value="true"/>
				<table>
					<tr><td colspan='2'><b>CRSF Serial Pins</td></tr>
					<tr><td width="30"></td><td>RX pin</td><td><input size='3' id='serial_rx' name='serial_rx' type='text'/></td></tr>
					<tr><td></td><td>TX pin </td><td><input size='3' id='serial_tx' name='serial_tx' type='text'/></td></tr>

					<tr><td colspan='2'><b>Radio Chip Pins & Options</td></tr>
					<tr><td></td><td>BUSY pin</td><td><input size='3' id='radio_busy' name='radio_busy' type='text'/></td></tr>
					<tr><td></td><td>DIO0 pin</td><td><input size='3' id='radio_dio0' name='radio_dio0' type='text'/></td></tr>
					<tr><td></td><td>DIO1 pin</td><td><input size='3' id='radio_dio1' name='radio_dio1' type='text'/></td></tr>
					<tr><td></td><td>DIO2 pin</td><td><input size='3' id='radio_dio2' name='radio_dio2' type='text'/></td></tr>
					<tr><td></td><td>MISO pin</td><td><input size='3' id='radio_miso' name='radio_miso' type='text'/></td></tr>
					<tr><td></td><td>MOSI pin</td><td><input size='3' id='radio_mosi' name='radio_mosi' type='text'/></td></tr>
					<tr><td></td><td>NSS pin</td><td><input size='3' id='radio_nss' name='radio_nss' type='text'/></td></tr>
					<tr><td></td><td>RST pin</td><td><input size='3' id='radio_rst' name='radio_rst' type='text'/></td></tr>
					<tr><td></td><td>SCK pin</td><td><input size='3' id='radio_sck' name='radio_sck' type='text'/></td></tr>
					<tr><td></td><td>BUSY_2 pin</td><td><input size='3' id='radio_busy_2' name='radio_busy_2' type='text'/></td>Busy pin for second SX1280</tr>
					<tr><td></td><td>DIO1_2 pin</td><td><input size='3' id='radio_dio1_2' name='radio_dio1_2' type='text'/></td>Interrupt pin for second SX1280</tr>
					<tr><td></td><td>NSS_2 pin</td><td><input size='3' id='radio_nss_2' name='radio_nss_2' type='text'/></td><td>Chip select pin for second SX1280</td></tr>
					<tr><td></td><td>DCDC enabled</td><td><input size='3' id='radio_dcdc' name='radio_dcdc' type='checkbox'/></td></tr>
					<tr><td></td><td>RFO_HF enabled</td><td><input size='3' id='radio_rfo_hf' name='radio_rfo_hf' type='checkbox'/></td></tr>

					<tr><td colspan='2'><b>Radio Antenna</td></tr>
					<tr><td></td><td>SELECT pin</td><td><input size='3' id='ant_select' name='ant_select' type='text'/></td></tr>
					<tr><td></td><td>CTRL1 pin</td><td><input size='3' id='ant_ctrl1' name='ant_ctrl1' type='text'/></td></tr>
					<tr><td></td><td>CTRL2 pin</td><td><input size='3' id='ant_ctrl2' name='ant_ctrl2' type='text'/></td></tr>

					<tr><td colspan='2'><b>Radio Power</td></tr>
					<tr><td></td><td>PA enable pin</td><td><input size='3' id='power_enable' name='power_enable' type='text'/></td></tr>
					<tr><td></td><td>APC1 pin</td><td><input size='3' id='power_apc1' name='power_apc1' type='text'/></td></tr>
					<tr><td></td><td>APC2 pin</td><td><input size='3' id='power_apc2' name='power_apc2' type='text'/></td></tr>
					<tr><td></td><td>RXEN pin</td><td><input size='3' id='power_rxen' name='power_rxen' type='text'/></td></tr>
					<tr><td></td><td>TXEN pin</td><td><input size='3' id='power_txen' name='power_txen' type='text'/></td></tr>
					<tr><td></td><td>RXEN_2 pin</td><td><input size='3' id='power_rxen_2' name='power_rxen_2' type='text'/></td></tr>
					<tr><td></td><td>TXEN_2 pin</td><td><input size='3' id='power_txen_2' name='power_txen_2' type='text'/></td></tr>
					<tr><td></td><td>Min Power</td><td>
						<select id='power_min' name='power_min'>
							<option value='0'>10mW</option>
							<option value='1'>25mW</option>
							<option value='2'>50mW</option>
							<option value='3'>100mW</option>
							<option value='4'>250mW</option>
							<option value='5'>500mW</option>
							<option value='6'>1000mW</option>
							<option value='7'>2000mW</option>
						</select>
					</td></tr>
					<tr><td></td><td>High Power</td><td>
						<select id='power_high' name='power_high'>
							<option value='0'>10mW</option>
							<option value='1'>25mW</option>
							<option value='2'>50mW</option>
							<option value='3'>100mW</option>
							<option value='4'>250mW</option>
							<option value='5'>500mW</option>
							<option value='6'>1000mW</option>
							<option value='7'>2000mW</option>
						</select>
					</td></tr>
					<tr><td></td><td>Max Power</td><td>
						<select id='power_max' name='power_max'>
							<option value='0'>10mW</option>
							<option value='1'>25mW</option>
							<option value='2'>50mW</option>
							<option value='3'>100mW</option>
							<option value='4'>250mW</option>
							<option value='5'>500mW</option>
							<option value='6'>1000mW</option>
							<option value='7'>2000mW</option>
						</select>
					</td></tr>
					<tr><td></td><td>Default Power</td><td>
						<select id='power_default' name='power_default'>
							<option value='0'>10mW</option>
							<option value='1'>25mW</option>
							<option value='2'>50mW</option>
							<option value='3'>100mW</option>
							<option value='4'>250mW</option>
							<option value='5'>500mW</option>
							<option value='6'>1000mW</option>
							<option value='7'>2000mW</option>
						</select>
					</td></tr>
					<tr><td></td><td>Power Level control</td><td>
						<select id='power_control' name='power_control'>
							<option value='0'>via Radio Chip</option>
							<!--<option value='1'>ANALOG</option>
							<option value='2'>DAC</option>-->
							<option value='3'>DACWRITE</option>
						</select>
					</td></tr>
					<tr><td></td><td>Level Value(s)</td><td><input size='40' id='power_values' name='power_values' type='text' class='array'/></td></tr>

					<tr><td colspan='2'><b>Radio Power Detection</td></tr>
					<tr><td></td><td>PDET pin</td><td><input size='3' id='power_pdet' name='power_pdet' type='text'/></td></tr>
					<tr><td></td><td>Intercept</td><td><input size='20' id='power_pdet_intercept' name='power_pdet_intercept' type='text'/></td></tr>
					<tr><td></td><td>Slope</td><td><input size='20' id='power_pdet_slope' name='power_pdet_slope' type='text'/></td></tr>
@@if isTX:
					<tr><td colspan='2'><b>Analog Joystick</td></tr>
					<tr><td></td><td>ADC pin</td><td><input size='3' id='joystick' name='joystick' type='text'/></td></tr>
					<tr><td></td><td>Values</td><td><input size='40' id='joystick_values' name='joystick_values' type='text' class='array'/></td></tr>

					<tr><td colspan='2'><b>Digital Joystick</td></tr>
					<tr><td></td><td>Pin 1</td><td><input size='3' id='five_way1' name='five_way1' type='text'/></td></tr>
					<tr><td></td><td>Pin 2</td><td><input size='3' id='five_way2' name='five_way2' type='text'/></td></tr>
					<tr><td></td><td>Pin 3</td><td><input size='3' id='five_way3' name='five_way3' type='text'/></td></tr>
@@end
					<tr><td colspan='2'><b>Button(s)</td></tr>
					<tr><td></td><td>Button 1 pin</td><td><input size='3' id='button' name='button' type='text'/></td></tr>

					<tr><td colspan='2'><b>Mood Lighting</td></tr>
					<tr><td></td><td>RGB LED pin</td><td><input size='3' id='led_rgb' name='led_rgb' type='text'/></td></tr>
					<tr><td></td><td>RGB LED is GRB</td><td><input size='3' id='led_rgb_isgrb' name='led_rgb_isgrb' type='checkbox'/></td></tr>
					<tr><td></td><td>RGB indexes for Status</td><td><input size='40' id='ledidx_rgb_status' name='ledidx_rgb_status' type='text' class='array'/></td><td>Indexes into the "string" of RGB LEDs (if empty then only LED at 0 is used)</td></tr>
@@if not isTX:
					<tr><td></td><td>RGB indexes for VTX Status</td><td><input size='40' id='ledidx_rgb_vtx' name='ledidx_rgb_vtx' type='text' class='array'/></td><td>Indexes into the "string" of RGB LEDs (if empty then no VTX status)</td></tr>
@@end
					<tr><td></td><td>RGB indexes for Boot animation</td><td><input size='40' id='ledidx_rgb_boot' name='ledidx_rgb_boot' type='text' class='array'/></td><td>Indexes into the "string" of RGB LEDs (if empty status indexes are used)</td></tr>
					<tr><td></td><td>LED pin</td><td><input size='3' id='led' name='led' type='text'/></td><td>Only use when only a single LED is used</td></tr>
					<tr><td></td><td>Red LED pin</td><td><input size='3' id='led_red' name='led_red' type='text'/></td></tr>
					<tr><td></td><td>Red LED inverted</td><td><input size='3' id='led_red_invert' name='led_red_invert' type='checkbox'/></td></tr>
					<tr><td></td><td>Green LED pin</td><td><input size='3' id='led_green' name='led_green' type='text'/></td></tr>
					<tr><td></td><td>Green LED inverted</td><td><input size='3' id='led_green_invert' name='led_green_invert' type='checkbox'/></td></tr>
					<tr><td></td><td>Blue LED pin</td><td><input size='3' id='led_blue' name='led_blue' type='text'/></td></tr>
					<!-- SIYI things!
					<tr><td></td><td>Green/Red LED pin</td><td><input size='3' id='led_green_red' name='led_green_red' type='text'/></td></tr>
					<tr><td></td><td>Red/Green LED pin</td><td><input size='3' id='led_red_green' name='led_red_green' type='text'/></td></tr>
					-->
@@if isTX:
					<tr><td colspan='2'><b>OLED/TFT (Crotch TV)</td></tr>
					<tr><td></td><td>Screen type</td><td>
						<select id='screen_type' name='screen_type'>
							<option value='0'>None</option>
							<option value='1'>I2C OLED</option>
							<option value='2'>SPI OLED</option>
							<option value='3'>SPI OLED (small)</option>
							<option value='4'>SPI TFT</option>
						</select>
					</td></tr>
					<tr><td></td><td>180 rotation</td><td><input size='3' id='screen_reversed' name='screen_reversed' type='checkbox'/></td></tr>
					<tr><td></td><td>CS pin</td><td><input size='3' id='screen_cs' name='screen_cs' type='text'/></td><td>Chip Select (SPI)</td></tr>
					<tr><td></td><td>DC pin</td><td><input size='3' id='screen_dc' name='screen_dc' type='text'/></td><td>Data/Command Select (SPI)</td></tr>
					<tr><td></td><td>MOSI pin</td><td><input size='3' id='screen_mosi' name='screen_mosi' type='text'/></td><td>Data (SPI)</td></tr>
					<tr><td></td><td>RST pin</td><td><input size='3' id='screen_rst' name='screen_rst' type='text'/></td><td>Reset</td></tr>
					<tr><td></td><td>SCK pin</td><td><input size='3' id='screen_sck' name='screen_sck' type='text'/></td><td>Clock</td></tr>
					<tr><td></td><td>SDA pin</td><td><input size='3' id='screen_sda' name='screen_sda' type='text'/></td><td>Data (I2C)</td></tr>
					<tr><td></td><td>BL pin</td><td><input size='3' id='screen_bl' name='screen_bl' type='text'/></td><td>Backlight</td></tr>

					<tr><td colspan='2'><b>Backpack / Logging</td></tr>
					<tr><td></td><td>Enable Backpack</td><td><input size='3' id='use_backpack' name='use_backpack' type='checkbox'/></td></tr>
					<tr><td></td><td>Baud Rate</td><td><input size='10' id='debug_backpack_baud' name='debug_backpack_baud' type='text'/></td><td>460800 for backpack passthrough flashing</td></tr>
					<tr><td></td><td>RX pin</td><td><input size='3' id='debug_backpack_rx' name='debug_backpack_rx' type='text'/></td></tr>
					<tr><td></td><td>TX pin</td><td><input size='3' id='debug_backpack_tx' name='debug_backpack_tx' type='text'/></td></tr>
					<tr><td></td><td>BOOT pin</td><td><input size='3' id='backpack_boot' name='backpack_boot' type='text'/></td><td>Pin connected to GPIO0 pin on backpack ESP8285</td></tr>
					<tr><td></td><td>EN pin</td><td><input size='3' id='backpack_en' name='backpack_en' type='text'/></td><td>Pin connected to EN pin on backpack ESP8285</td></tr>
					<tr><td></td><td>Passthrough baud</td><td><input size='7' id='passthrough_baud' name='passthrough_baud' type='text'/></td><td>Baud rate to flash the backpack ESP8285 (default is to use the baud rate above)</td></tr>

					<tr><td colspan='2'><b>I2C & Misc Devices</td></tr>
					<tr><td></td><td>SCL pin</td><td><input size='3' id='i2c_scl' name='i2c_scl' type='text'/></td></tr>
					<tr><td></td><td>SDA pin</td><td><input size='3' id='i2c_sda' name='i2c_sda' type='text'/></td></tr>
					<tr><td></td><td>Buzzer pin</td><td><input size='3' id='misc_buzzer' name='misc_buzzer' type='text'/></td></tr>
					<tr><td></td><td>Fan enable pin</td><td><input size='3' id='misc_fan_en' name='misc_fan_en' type='text'/></td></tr>
					<tr><td></td><td>Has STK8xxx G-sensor</td><td><input size='3' id='gsensor_stk8xxx' name='gsensor_stk8xxx' type='checkbox'/></td></tr>
					<tr><td></td><td>G-sensor interrupt pin</td><td><input size='3' id='misc_gsensor_int' name='misc_gsensor_int' type='text'/></td></tr>
					<tr><td></td><td>Has LM75A Thermal sensor</td><td><input size='3' id='thermal_lm75a' name='thermal_lm75a' type='checkbox'/></td></tr>
@@end
@@if not isTX:
					<tr><td colspan='2'><b>PWM</td></tr>
					<tr><td></td><td>PWM output pins</td><td><input size='40' id='pwm_outputs' name='pwm_outputs' type='text' class='array'/></td></tr>

					<tr><td colspan='2'><b>VBat</td></tr>
					<tr><td></td><td>VBat pin</td><td><input size='3' id='vbat' name='vbat' type='text'/></td></tr>
					<tr><td></td><td>VBat offset</td><td><input size='7' id='vbat_offset' name='vbat_offset' type='text'/></td></tr>
					<tr><td></td><td>VBat scale</td><td><input size='7' id='vbat_scale' name='vbat_scale' type='text'/></td></tr>

					<tr><td colspan='2'><b>SPI VTX</td></tr>
					<tr><td></td><td>RF amp PWM pin</td><td><input size='3' id='vtx_amp_pwm' name='vtx_amp_pwm' type='text'/></td></tr>
					<tr><td></td><td>RF amp VPD pin</td><td><input size='3' id='vtx_amp_vpd' name='vtx_amp_vpd' type='text'/></td></tr>
					<tr><td></td><td>RF amp VREF pin</td><td><input size='3' id='vtx_amp_vref' name='vtx_amp_vref' type='text'/></td></tr>
					<tr><td></td><td>SPI NSS pin</td><td><input size='3' id='vtx_nss' name='vtx_nss' type='text'/></td></tr>
					<tr><td></td><td>SPI SCK pin</td><td><input size='3' id='vtx_sck' name='vtx_sck' type='text'/></td><td>If this pin is undefined, then the SPI bus is shared with the radio chip</td></tr>
					<tr><td></td><td>SPI MISO pin</td><td><input size='3' id='vtx_miso' name='vtx_miso' type='text'/></td></tr>
					<tr><td></td><td>SPI MOSI pin</td><td><input size='3' id='vtx_mosi' name='vtx_mosi' type='text'/></td></tr>
					<tr><td></td><td>25mW VPD interpolation values</td><td><input size='40' id='vtx_amp_vpd_25mW' name='vtx_amp_vpd_25mW' type='text' class='array'/></td></tr>
					<tr><td></td><td>100mW VPD interpolation values</td><td><input size='40' id='vtx_amp_vpd_100mW' name='vtx_amp_vpd_100mW' type='text' class='array'/></td></tr>
@@end
				</table>
				<br>
				<input type='button' value='Save Target Configuration' class='mui-btn mui-btn--primary' onclick="submitHardwareSettings()"/>
			</form>
		</div>
	</div>
</body>
<script src="hardware.js"></script>
</html>
